import os
from PySide6.QtGui import QIcon, QPixmap
from PySide6.QtCore import QByteArray, QBuffer, QIODevice

# 编码的图标数据，Base64格式
COLLAPSE_ICON_DATA = """
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAAoUlEQVQ4je3SIQ7CQBCF4Q+SAQQKgUMgcBjuQHAAJKLqECguQlVVPQGGBIFB1GAIogZHQJCQlCYNmy67JQI8MWLe/H8mMyNJmrBGhV50PtAM7g19s4asmVBghxl6bnxGbg2swAIzNIJ5hRkPUZPnBsdgcIrO0y+K5hiiH5/3COYrJm+aZn8UD8E8+aUow6TxHaTooouWW6Pil61QYqFdJU8cXN6vZw9ZvfQAAAAASUVORK5CYII=
"""

EXPAND_ICON_DATA = """
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAAf0lEQVQ4je3SsQ2DMBBA0ScWYAZGyAiMkBEyAiNkhIzACKlTsAE7ZISMgGQJA1+KREpDCrC5F5+v+HSSfukCDJhCXzDiDWt4MxIGPJqfE84uuPgSfskSd2vgcgvYp1tYJJ5ZXvAIXKLQm9bkfdKhT3L7Qn4hVSgxhxbYYkIVpvjGL+cDvS5hgW9HsCAAAAAASUVORK5CYII=
"""

def get_default_icon(name):
    """获取默认图标"""
    if name == "collapse":
        data = COLLAPSE_ICON_DATA
    elif name == "expand":
        data = EXPAND_ICON_DATA
    else:
        return None
    
    # 创建图标
    pixmap = QPixmap()
    pixmap.loadFromData(QByteArray.fromBase64(data.strip().encode()))
    icon = QIcon(pixmap)
    
    # 保存到文件
    icons_dir = "icons"
    os.makedirs(icons_dir, exist_ok=True)
    
    filename = os.path.join(icons_dir, f"{name}.png")
    if not os.path.exists(filename):
        pixmap.save(filename)
    
    return icon 